/**
 * @file models/retail.js
 * @author
 */
import { routerRedux } from 'dva/router';
import api from '../api';
import moment from 'moment'


export default {
	namespace: 'retailEducationDetail',
	state: {

	},
	subscriptions : {
		setup({dispatch, history}) {
			history.listen(({ pathname, query }) => {
				// 没有参数时，向后端请求数据，并且改变query
				if( pathname === '/retailEducationDetail' ){
					dispatch({type: 'whetherRequest',payload:query,pathname})
				}
			})
		}
	},
	effects : {

		* whetherRequest({
				payload,pathname
			}, { put,select}) {
				yield put({
					type: 'query',
					payload
				})
		},
		* query({payload}, {call, put,select}) {
			const {
				trader,
        id,
			} = payload;

			if(trader) {
				// 首先获取基础数据
				const retailEducationDetail = yield call(api.retail.getRetailEducationDetail, id, { trader });

        yield put({
          type: 'querySuccess',
          payload:{
            detail: retailEducationDetail.data,
          }
        })
			}
		},
	},
	reducers : {
		setState(state, {payload}) {
			return {
				...state,
				...payload
			}
		},
		querySuccess(state, {payload}) {
			return {
				...state,
				...payload
			}
		}

	}
};
